core: Drain fdatasync() API into libgsystem
authorColin Walters <walters@verbum.org>
Fri, 4 Jan 2013 22:25:32 +0000 (17:25 -0500)
committerColin Walters <walters@verbum.org>
Fri, 4 Jan 2013 22:25:32 +0000 (17:25 -0500)
Just code cleanup.

src/libgsystem
src/libostree/ostree-repo.c
src/libotutil/ot-unix-utils.c
src/libotutil/ot-unix-utils.h

index b11ad335f459e3c61b317308da57de441660efd0..6c736d9309d5ffbc60ed0a58e21f0f8ad609ba10 160000 (submodule)
@@ -1 +1 @@
-Subproject commit b11ad335f459e3c61b317308da57de441660efd0
+Subproject commit 6c736d9309d5ffbc60ed0a58e21f0f8ad609ba10
index e0c7ab68db35edf25b1d6cb2d30387b62287ab30..ef49636c9f39938cb5cc0a6cfea8f6b9ab7fec8c 100644 (file)
@@ -742,37 +742,6 @@ ostree_repo_get_archive_content_path (OstreeRepo    *self,
   return g_file_resolve_relative_path (self->repodir, path);
 }
 
-/**
- * ensure_file_data_synced:
- *
- * Ensure that in case of a power cut, these files have the data we
- * want.   See http://lwn.net/Articles/322823/
- */
-static gboolean
-ensure_file_data_synced (GFile         *file,
-                         GCancellable  *cancellable,
-                         GError       **error)
-{
-  gboolean ret = FALSE;
-  int fd = -1;
-
-  if (!ot_unix_open_noatime (gs_file_get_path_cached (file), &fd, error))
-    goto out;
-
-  if (!ot_unix_fdatasync (fd, error))
-    goto out;
-
-  if (!ot_unix_close (fd, error))
-    goto out;
-  fd = -1;
-
-  ret = TRUE;
- out:
-  if (fd != -1)
-    (void) close (fd);
-  return ret;
-}
-
 static gboolean
 commit_loose_object_impl (OstreeRepo        *self,
                           GFile             *tempfile_path,
@@ -790,7 +759,10 @@ commit_loose_object_impl (OstreeRepo        *self,
 
   if (is_regular)
     {
-      if (!ensure_file_data_synced (tempfile_path, cancellable, error))
+      /* Ensure that in case of a power cut, these files have the data we
+       * want.   See http://lwn.net/Articles/322823/
+       */
+      if (!gs_file_sync_data (tempfile_path, cancellable, error))
         goto out;
     }
   
@@ -3159,7 +3131,7 @@ checkout_file_from_input (GFile          *file,
 
           if (g_file_info_get_file_type (temp_info) == G_FILE_TYPE_REGULAR)
             {
-              if (!ensure_file_data_synced (temp_file, cancellable, error))
+              if (!gs_file_sync_data (temp_file, cancellable, error))
                 goto out;
             }
 
@@ -3178,7 +3150,7 @@ checkout_file_from_input (GFile          *file,
 
       if (g_file_info_get_file_type (temp_info) == G_FILE_TYPE_REGULAR)
         {
-          if (!ensure_file_data_synced (file, cancellable, error))
+          if (!gs_file_sync_data (file, cancellable, error))
             goto out;
         }
     }
index 3b0645f9a9786cafe28386136e0a6f8f952fe2ce..d4793019e1ca48b37b91f22842f0c3620bda038a 100644 (file)
@@ -190,26 +190,6 @@ ot_util_fatal_gerror (GError *error)
   ot_util_fatal_literal (error->message);
 }
 
-/**
- * ot_unix_fdatasync:
- *
- * Like fdatasync(), but uses #GError, and handles EINTR.
- */
-gboolean
-ot_unix_fdatasync (int fd, GError **error)
-{
-  int result;
-  do
-    result = fdatasync (fd);
-  while (G_UNLIKELY (result != 0 && errno == EINTR));
-  if (result != 0)
-    {
-      ot_util_set_error_from_errno (error, errno);
-      return FALSE;
-    }
-  return TRUE;
-}
-
 /**
  * ot_unix_close:
  *
index 18f07494e76fb0ff2edfdb8852b9314eb8d7e16a..9a8c3ac6bd8cb797977355638b9ddee82b5217ba 100644 (file)
@@ -55,8 +55,6 @@ gboolean ot_unix_open (const char *path,
                        int        *out_fd,
                        GError    **error);
 
-gboolean ot_unix_fdatasync (int fd, GError **error);
-
 gboolean ot_unix_close (int fd, GError **error);
 
 gboolean ot_unix_open_noatime (const char *path, int *out_fd, GError **error);